// 数组转对象
export function ArrToObj(data) {
  const Obj = {};
  data.forEach(e => {
    Obj[e.name] = e.value;
  });
  return Obj;
}

// geo 线的数据
export function geoLine(data) {
  data.features = data.features.map(e => {
    e.geometry.type = 'LineString';
    e.geometry.coordinates = e.geometry.coordinates[0][0];
    return {
      ...e
    };
  });
  return data;
}

export function formateData(data) {
  return data.features.map(e => {
    return {
      name: e.properties.name,
      center: e.properties.centroid,
      value: e.properties.value,
      coordinates: e.geometry.coordinates[0],
      properties: e.properties
    };
  });
}

export function formatePointData(data) {
  return data.features.map(e => {
    return {
      name: e.properties.name,
      value: e.properties.value,
      center: e.properties.centroid,
      coordinates: e.geometry.coordinates,
      properties: e.properties
    };
  });
}

export function formateDataLine(data) {
  return data.features.map(e => {
    return {
      lnglat: e.geometry.coordinates[0][0]
    };
  });
}

export const Detector = {
  webgl: (function() {
      try {
          const canvas = document.createElement('canvas');
          return !!(window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')));
      } catch (e) {
          return false;
      }
  })()
};
